package Thread;

public class Demo4 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            System.out.println("hello t");
        });
        t.start();
        try {
            //睡眠1000ms,也可以称为阻塞1000ms
             Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("hello main");
    }
    public static void main2(String[] args) {
        //获取当前线程的引用
        Thread t = Thread.currentThread();
        //通过当前线程的引用调用当前线程的名字
        System.out.println("当前线程名字 : "+t.getName());
    }
    public static void main1(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t 线程正在运行");
            }
        });
        System.out.println("t线程是否存活 "+t.isAlive());
        t.start();
        System.out.println("t线程是否存活 "+t.isAlive());

        try {
            Thread.sleep(1000);
            System.out.println("t线程是否存活 "+t.isAlive());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
